package com.kemai.test.event.click

import android.os.Bundle
import android.util.Log
import android.view.MotionEvent
import android.view.View
import android.widget.Button
import android.widget.Toast
import com.kemai.common.ui.BaseActivity
import com.kemai.test.R

class ClickEventActivity:BaseActivity(){
    private lateinit var btn_click: Button
    private val TAG = "zhaoshanshan"
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_click_event)
        setTiTle("测试点击事件分发")
        init()

    }
    override fun init() {
        findViewById()
        setOnClickListener()
        setOnTouchListener()

    }

    override fun findViewById() {
        super.findViewById()
        btn_click = findViewById(R.id.btn_click);

    }

    override fun setOnClickListener() {
        btn_click.setOnClickListener(this)

    }

    override fun setOnTouchListener() {
        btn_click.setOnTouchListener(this)
    }

    override fun onClick(v: View?) {
        super.onClick(v)
        when(v?.id){
           R.id.btn_click ->{
               Log.e(TAG, "onClick")
               Toast.makeText(ClickEventActivity@this,"查看控制台logo日志",Toast.LENGTH_SHORT).show()
           }
        }
    }

    override fun onTouch(v: View?, event: MotionEvent?): Boolean {
        when(v?.id){
            R.id.btn_click ->{
                Log.e(TAG, "onTouch: " + event?.action);
            }
        }
        return false
    }

    override fun dispatchTouchEvent(ev: MotionEvent?): Boolean {
        Log.e(TAG, "ClickEventActivity的dispatchTouchEvent: ")
        return super.dispatchTouchEvent(ev)//向上层层传递
        //return false
    }

    override fun onTouchEvent(event: MotionEvent?): Boolean {
        Log.e(TAG, "ClickEventActivity的onTouchEvent: "+event?.action)
        return super.onTouchEvent(event)
    }

}